package August;

import java.util.Locale;
import java.util.Scanner;

public class Day0807 {
    //星际密码
    public static void main1(String[] args) {
        //初始化斐波那契数组
        int[] array = new int[10001];
        array[1] = 1;
        array[2] = 2;
        for (int i = 3; i < 10001; i++) {
            array[i] = array[i-1]+array[i-2];
            array[i] = array[i] % 10000;
        }


        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            int n = scanner.nextInt();
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < n; i++) {
                int temp = scanner.nextInt();
                stringBuilder.append(String.format("%04d",array[temp]));
            }
            System.out.println(stringBuilder);
        }
    }





    //数根
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String n = scanner.nextLine();

            while (n.length() > 1){
                int sum = 0;
                for (int i = 0; i < n.length(); i++) {
                    sum += n.charAt(i) - '0';
                }
                n = String.valueOf(sum);
            }
            System.out.println(n);
        }
    }

}

